package com.ybkj.o2o.zhuanche.service.impl;

import com.ybkj.o2o.zhuanche.entity.OrderOrbit;
import com.ybkj.o2o.zhuanche.entity.OrderOrbitCriteria;
import com.ybkj.o2o.zhuanche.mapper.BaseMapper;
import com.ybkj.o2o.zhuanche.mapper.OrderOrbitMapper;
import com.ybkj.o2o.zhuanche.service.OrderOrbitService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class DefaultOrderOrbitService extends
    AbstractBaseService<OrderOrbit, OrderOrbitCriteria, Long> implements OrderOrbitService {

  @Autowired
  private OrderOrbitMapper orderOrbitMapper;

  @Override
  public BaseMapper<OrderOrbit, OrderOrbitCriteria, Long> getMapper() {

    return orderOrbitMapper;
  }

  @Override
  public int insert(OrderOrbit orderOrbit) {
    orderOrbit.setCreated(new Date());
    orderOrbit.setUpdated(new Date());
    return super.insert(orderOrbit);
  }

  @Override
  public int update(OrderOrbit orderOrbit) {

    orderOrbit.setUpdated(new Date());
    return super.update(orderOrbit);
  }

  @Override
  public OrderOrbit findByOrderId(Long orderId) {
    OrderOrbit orbit = new OrderOrbit();
    OrderOrbitCriteria example = new OrderOrbitCriteria();
    example.createCriteria().andOrderIdEqualTo(orderId);
    List<OrderOrbit> list = orderOrbitMapper.selectByExample(example);
    if (list != null && list.size() != 0) {
      orbit = list.get(0);
    }
    return orbit;
  }

}
